#include "rgb2gray.h"

void rgb2gray(RGB color_img[HEIGHT][WIDTH], unsigned char gray_img[HEIGHT][WIDTH]) {
    for (int i = 0; i < HEIGHT; i++) {
        for (int j = 0; j < WIDTH; j++) {
            unsigned char r = color_img[i][j].r;
            unsigned char g = color_img[i][j].g;
            unsigned char b = color_img[i][j].b;

            // gray_value = 0.299R + 0.587G + 0.114B
            gray_img[i][j] = (unsigned char)((r * 77 + g * 150 + b * 29) >> 8); // 77/256 ≈ 0.299
        }
    }
}
